*RCRA Nationwide Hedonic Study
*Hedonic regressions
*Created: 5/21/2020
*Created by: Dennis Guignet
*Last Revised: 05/22/2023
*Last Revised by: Dennis Guignet

********************************************************************************
 
*This do-file takes the completed transaction dataset of all transactions and
*	estimates the primary hedonic regressions comparing the treated group (0-750m) 
*	and control group (750-1500). Performs regressions using fully unweighted 
*	and CEM weighted samples. Ultimately, the model results here are used to 
*	populate Table A8 in Appendix D.2, and most importantly, the main regression 
*	results in Table 3 of the main text. The results from Model 1 below are also 
*	used to later create the distance gradients displayed in Figure 4 of the 
*	main text.

********************************************************************************
********************************************************************************

*set empty cells for factor variables to drop
set emptycells drop
clear all
*increase max variables allowed b/c factor variables
set maxvar 100000

*set key global variable groups

*house structure and local neighborhood vars
global house lnacres lnacres_miss stories stories_miss bathtot bathtot_miss lnsqft ///
	lnsqft_miss age agesq age_miss p_nbdev_2011_200 p_nbdev_2011_500 hwy500m
	*Note: Create all interactions and fixed effects in reghdfe command below.


********************************************************************************
********************************************************************************

*Estimate Models 1' and 2' in Table A8 of Appendix D.2. These initial models allow 
*	the price effects to vary by each 250-meter bin within the treatment zone of
*	0-750 meters.


*Model 1' 

*Bring in full dataset of transactions within 5km of any TSDF.
use "$salesfolder\All_Sales_Final_Cleaned_TSD5k", clear
count		

*Set corresponding global variables 	
	
*code up global variable for TSD counts	
local vars  cntTSD
foreach v of local vars {
	global `v' `v'0_250 `v'250_500 `v'500_750 `v'750_1000 ///
		`v'1000_1250 `v'1250_1500 `v'1500_1750 `v'1750_2000 ///
		`v'2000_2250 `v'2250_2500 `v'2500_2750 `v'2750_3000 ///
		`v'3000_3250 `v'3250_3500 `v'3500_3750 `v'3750_4000 ///
		`v'4000_4250 `v'4250_4500 `v'4500_4750 `v'4750_5000 
	}
	
*Next code up global variables of stage dummies for individual treatment bins.	
local stages pre mid post 
foreach s of local stages {
	global d`s'CA d`s'CA0_250 d`s'CA250_500 d`s'CA500_750 d`s'CA750_1500 d`s'CA1500_5000
	}	
	*Note: First three bins denote treatment zone, the 750-1500 meter bin is the 
	*	control group. The 1500-5000 bin is included, but to control for other
	*	temporally correlated factors in the broader neighborhood, but the coefficients
	*	are never used. Those 1500-5000 transactions are included mainly to help
	*	identify county-specific time trends. 
	

*Model with all TSD 5k sample.
reghdfe lnrprice $cntTSD $dpreCA $dmidCA $dpostCA, ///
	absorb(i.mycntyid#i.tranyr i.mycntyid#i.quarter i.mytractid ///
	i.mycntyid#i.tranyr#c.($house)) vce(cluster mycntyid)  compact poolsize(20)
eststo m1
estimates save "$raw_resultsfolder\m1", replace

estimates use "$raw_resultsfolder\m1"
*H0: Triple differences CA open (post) estimate 0-750 jointly significant
testnl ((exp((_b[dmidCA0_250]-_b[dpreCA0_250])-(_b[dmidCA750_1500]-_b[dpreCA750_1500]))-1)*100) ///
	= ((exp((_b[dmidCA250_500]-_b[dpreCA250_500])-(_b[dmidCA750_1500]-_b[dpreCA750_1500]))-1)*100) ///
	= ((exp((_b[dmidCA500_750]-_b[dpreCA500_750])-(_b[dmidCA750_1500]-_b[dpreCA750_1500]))-1)*100) ///
	= 0
	*Note: Reject null that CA opening effects jointly equal zero 
	*	i.e., they're jointly significnt (ch2(3)=6.59, p=0.0863)
	
testnl ((exp((_b[dpostCA0_250]-_b[dmidCA0_250])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100) ///
	= ((exp((_b[dpostCA250_500]-_b[dmidCA250_500])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100) ///
	= ((exp((_b[dpostCA500_750]-_b[dmidCA500_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100) ///
	=0
	*Note: Reject null that CA completion effects jointly equal zero 
	*	i.e., they're jointly signifiant (ch2(3)=9.79, p=0.0205)
	
*H0: Triple differences CA open (post) estimate 0-750 statistically equal
testnl ((exp((_b[dmidCA0_250]-_b[dpreCA0_250])-(_b[dmidCA750_1500]-_b[dpreCA750_1500]))-1)*100) ///
	= ((exp((_b[dmidCA250_500]-_b[dpreCA250_500])-(_b[dmidCA750_1500]-_b[dpreCA750_1500]))-1)*100) ///
	= ((exp((_b[dmidCA500_750]-_b[dpreCA500_750])-(_b[dmidCA750_1500]-_b[dpreCA750_1500]))-1)*100)
	*Note: Fail to reject null that CA opening effects are equal across nearest 
	*	three distance bins (chi(2)=0.38, p=0.8287)
	
testnl ((exp((_b[dpostCA0_250]-_b[dmidCA0_250])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100) ///
	= ((exp((_b[dpostCA250_500]-_b[dmidCA250_500])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100) ///
	= ((exp((_b[dpostCA500_750]-_b[dmidCA500_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100)
	*Note: Fail to reject null that CA completion effects are equal across nearest 
	*	three distance bins (chi(2)=0.63, p=0.7312)


*Estimates triple diff treatment effect estimates. This corresponds to Model 1'
*	results in Table A8 of Appendix D.2.
eststo TE1: nlcom ///
	(D3MidPre_0_250: ((exp((_b[dmidCA0_250]-_b[dpreCA0_250])-(_b[dmidCA750_1500]-_b[dpreCA750_1500]))-1)*100)) ///
	(D3MidPre_250_500: ((exp((_b[dmidCA250_500]-_b[dpreCA250_500])-(_b[dmidCA750_1500]-_b[dpreCA750_1500]))-1)*100)) ///
	(D3MidPre_500_750: ((exp((_b[dmidCA500_750]-_b[dpreCA500_750])-(_b[dmidCA750_1500]-_b[dpreCA750_1500]))-1)*100)) ///
	(D3PostMid_0_250: ((exp((_b[dpostCA0_250]-_b[dmidCA0_250])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100)) ///
	(D3PostMid_250_500: ((exp((_b[dpostCA250_500]-_b[dmidCA250_500])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100)) ///
	(D3PostMid_500_750: ((exp((_b[dpostCA500_750]-_b[dmidCA500_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100)),  post	


*Export regression results and ATT from DD and DDD calculations	
*regression model results
esttab m1 using "$resultsfolder/HedonicReg_Model1_NoCEM.csv", replace label csv compress nogaps nolines star (* 0.10 ** 0.05 *** 0.01) b(4) se(4) scalars(ll N_g) r2 ar2
*ATT Estimates
esttab TE1 using "$resultsfolder\TreatmentEffectEsts_Model1_NoCEM.csv", replace label csv compress nogaps nolines star (* 0.10 ** 0.05 *** 0.01) b(4) se(4) scalars(ll)



********************************************************************************

*Model 2' 

use "$salesfolder\All_Sales_Final_Cleaned_CA5k", replace

*Need to re-set CA global variables for this sample
local stages pre mid post 
foreach s of local stages {
	global d`s'CA d`s'CA0_250 d`s'CA250_500 d`s'CA500_750 d`s'CA750_1500 /*d`s'CA1500_5000*/
	}	
	*Note: First three bins denote treatment zone, the 750-1500 meter bin is the 
	*	control group. The 1500-5000 bin is omitted. It would likely run due to 
	*	multiple CAs around some sales, but interpretation odd because with this 
	*	"CA-only" sample, the previous omitted category of sales around TSDs with 
	*	no corrective action are now excluded.  	

*Model with tract FE, and county x year and county x quarter FEs. All CA 5k sample.
reghdfe lnrprice $cntTSD $dpreCA $dmidCA $dpostCA, ///
	absorb(i.mycntyid#i.tranyr i.mycntyid#i.quarter i.mytractid ///
	i.mycntyid#i.tranyr#c.($house)) vce(cluster mycntyid)  compact poolsize(20)
eststo m2
estimates save "$raw_resultsfolder\m2", replace	

estimates use "$raw_resultsfolder\m2"
*H0: Triple differences CA open (post) estimate 0-750 jointly significant
testnl ((exp((_b[dmidCA0_250]-_b[dpreCA0_250])-(_b[dmidCA750_1500]-_b[dpreCA750_1500]))-1)*100) ///
	= ((exp((_b[dmidCA250_500]-_b[dpreCA250_500])-(_b[dmidCA750_1500]-_b[dpreCA750_1500]))-1)*100) ///
	= ((exp((_b[dmidCA500_750]-_b[dpreCA500_750])-(_b[dmidCA750_1500]-_b[dpreCA750_1500]))-1)*100) ///
	= 0
	*Note: Reject null hypothesis that estimated CA opening effect across 
	*	bins are jointly equal to zero, suggesting estimates are jointly significant
	*	(chi2(3)=6.77, p=0.0795).
	
testnl ((exp((_b[dpostCA0_250]-_b[dmidCA0_250])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100) ///
	= ((exp((_b[dpostCA250_500]-_b[dmidCA250_500])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100) ///
	= ((exp((_b[dpostCA500_750]-_b[dmidCA500_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100) ///
	=0
	*Note: Reject null hypothesis that CA completion effect across bins are jointly
	*	equal to zero, suggesting estimates are jointly significant (chi2(3)=7.53, 0.0568).
	
*H0: Triple differences CA open (post) estimate 0-750 statistically equal
testnl ((exp((_b[dmidCA0_250]-_b[dpreCA0_250])-(_b[dmidCA750_1500]-_b[dpreCA750_1500]))-1)*100) ///
	= ((exp((_b[dmidCA250_500]-_b[dpreCA250_500])-(_b[dmidCA750_1500]-_b[dpreCA750_1500]))-1)*100) ///
	= ((exp((_b[dmidCA500_750]-_b[dpreCA500_750])-(_b[dmidCA750_1500]-_b[dpreCA750_1500]))-1)*100)	
	*Note: Fail to reject null that CA opening effects equal across treatment bins,
	*	thus supporting pooling (chi2(2)=0.15, p=0.9275).
	
testnl ((exp((_b[dpostCA0_250]-_b[dmidCA0_250])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100) ///
	= ((exp((_b[dpostCA250_500]-_b[dmidCA250_500])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100) ///
	= ((exp((_b[dpostCA500_750]-_b[dmidCA500_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100)
	*Note: Fail to reject null that CA opening effects equal across treatment bins,
	*	thus supporting pooling (chi2(2)=0.31, p=0.8549).
	

	
*Estimate corresponding intra-area DID treatment effect estimates. This 
*	corresponds to Model 2' results in Table A8 of Appendix D.2.
eststo TE2: nlcom ///
	(D3MidPre_0_250: ((exp((_b[dmidCA0_250]-_b[dpreCA0_250])-(_b[dmidCA750_1500]-_b[dpreCA750_1500]))-1)*100)) ///
	(D3MidPre_250_500: ((exp((_b[dmidCA250_500]-_b[dpreCA250_500])-(_b[dmidCA750_1500]-_b[dpreCA750_1500]))-1)*100)) ///
	(D3MidPre_500_750: ((exp((_b[dmidCA500_750]-_b[dpreCA500_750])-(_b[dmidCA750_1500]-_b[dpreCA750_1500]))-1)*100)) ///
	(D3PostMid_0_250: ((exp((_b[dpostCA0_250]-_b[dmidCA0_250])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100)) ///
	(D3PostMid_250_500: ((exp((_b[dpostCA250_500]-_b[dmidCA250_500])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100)) ///
	(D3PostMid_500_750: ((exp((_b[dpostCA500_750]-_b[dmidCA500_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100)),  post	


*Export regression results and ATT from DD and DDD calculations	
*regression model results
esttab m2 using "$resultsfolder/HedonicReg_Model2_NoCEM.csv", replace label csv compress nogaps nolines star (* 0.10 ** 0.05 *** 0.01) b(4) se(4) scalars(ll N_g) r2 ar2
*ATT Estimates
esttab TE2 using "$resultsfolder/TreatmentEffectEsts_Model2_NoCEM.csv", replace label csv compress nogaps nolines star (* 0.10 ** 0.05 *** 0.01) b(4) se(4) scalars(ll)



********************************************************************************
********************************************************************************

*Main hedonic regression results in final paper, including Models 1, 2, 3, and 4
*	from Table 3 in final manuscript. 

*Model 1: 0-750m pooled, w/ full sample of homes w/in 
*	5km of a TSD	
use "$salesfolder\All_Sales_Final_Cleaned_TSD5k", clear
count		

*Next code up global variables of stage dummies for individual treatment bins.	
local stages pre mid post 
foreach s of local stages {
	global d`s'CA d`s'CA0_750 d`s'CA750_1500 d`s'CA1500_5000
	}	

*Model with tract FE, and county x year and county x quarter FEs. All TSD 5k sample.
reghdfe lnrprice $cntTSD $dpreCA $dmidCA $dpostCA, ///
	absorb(i.mycntyid#i.tranyr i.mycntyid#i.quarter i.mytractid ///
	i.mycntyid#i.tranyr#c.($house)) vce(cluster mycntyid)  compact poolsize(20)
eststo m3 
estimates save "$raw_resultsfolder\m3", replace
*Estimate corresponding triple diff treatment effect estimates. This corresponds 
*	to Model 1 results in Table 3 of main text.
eststo TE3: nlcom ///
	(D3MidPre_0_750: ((exp((_b[dmidCA0_750]-_b[dpreCA0_750])-(_b[dmidCA750_1500]-_b[dpreCA750_1500]))-1)*100)) ///
	(D3PostMid_0_750: ((exp((_b[dpostCA0_750]-_b[dmidCA0_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100)),  post	


*Export regression results and ATT from DD and DDD calculations	
*regression model results
esttab m3 using "$resultsfolder/HedonicReg_Model3_NoCEM.csv", replace label csv compress nogaps nolines star (* 0.10 ** 0.05 *** 0.01) b(4) se(4) scalars(ll N_g) r2 ar2
*ATT Estimates
esttab TE3 using "$resultsfolder/TreatmentEffectEsts_Model3_NoCEM.csv", replace label csv compress nogaps nolines star (* 0.10 ** 0.05 *** 0.01) b(4) se(4) scalars(ll)


*Calculate % change in price associated with TSDFs (for Figure 4 in final 
*	manuscript).

*Calculate if 1, 2, or 3 TSDFs in each bin
estimates use "$raw_resultsfolder\m3"
eststo m3
local sites 1 2 3
foreach tsd of local sites {
	estimates restore m3
	eststo pctdp_`tsd'TSD: nlcom ///
		(pctdp_dTSD0_250: ((exp((_b[cntTSD0_250]*`tsd'))-1)*100)) ///
		(pctdp_dTSD250_500: ((exp((_b[cntTSD250_500]*`tsd'))-1)*100)) ///
		(pctdp_dTSD500_750: ((exp((_b[cntTSD500_750]*`tsd'))-1)*100)) ///
		(pctdp_dTSD750_1000: ((exp((_b[cntTSD750_1000]*`tsd'))-1)*100)) ///
		(pctdp_dTSD1000_1250: ((exp((_b[cntTSD1000_1250]*`tsd'))-1)*100)) ///
		(pctdp_dTSD1250_1500: ((exp((_b[cntTSD1250_1500]*`tsd'))-1)*100)) ///
		(pctdp_dTSD1500_1750: ((exp((_b[cntTSD1500_1750]*`tsd'))-1)*100)) ///
		(pctdp_dTSD1750_2000: ((exp((_b[cntTSD1750_2000]*`tsd'))-1)*100)) ///
		(pctdp_dTSD2000_2250: ((exp((_b[cntTSD2000_2250]*`tsd'))-1)*100)) ///
		(pctdp_dTSD2250_2500: ((exp((_b[cntTSD2250_2500]*`tsd'))-1)*100)) ///
		(pctdp_dTSD2500_2750: ((exp((_b[cntTSD2500_2750]*`tsd'))-1)*100)) ///
		(pctdp_dTSD2750_3000: ((exp((_b[cntTSD2750_3000]*`tsd'))-1)*100)) ///
		(pctdp_dTSD3000_3250: ((exp((_b[cntTSD3000_3250]*`tsd'))-1)*100)) ///
		(pctdp_dTSD3250_3500: ((exp((_b[cntTSD3250_3500]*`tsd'))-1)*100)) ///
		(pctdp_dTSD3500_3750: ((exp((_b[cntTSD3500_3750]*`tsd'))-1)*100)) ///
		(pctdp_dTSD3750_4000: ((exp((_b[cntTSD3750_4000]*`tsd'))-1)*100)) ///
		(pctdp_dTSD4000_4250: ((exp((_b[cntTSD4000_4250]*`tsd'))-1)*100)) ///
		(pctdp_dTSD4250_4500: ((exp((_b[cntTSD4250_4500]*`tsd'))-1)*100)) ///
		(pctdp_dTSD4500_4750: ((exp((_b[cntTSD4500_4750]*`tsd'))-1)*100)) ///
		(pctdp_dTSD4750_5000: ((exp((_b[cntTSD4750_5000]*`tsd'))-1)*100)), post
		}	

*export TSD gradient table and graph
esttab pctdp_1TSD pctdp_2TSD pctdp_3TSD using "$resultsfolder/TSD_DistGradient_forTable.csv", replace label csv compress nogaps nolines star (* 0.10 ** 0.05 *** 0.01) b(4) se(4) scalars(ll)	
esttab pctdp_1TSD using "$resultsfolder/DistGradient_forGraph_1TSD.csv", replace label plain csv compress nogaps nolines nostar b(4) ci(4) wide noparentheses 
esttab pctdp_2TSD using "$resultsfolder/DistGradient_forGraph_2TSD.csv", replace label plain csv compress nogaps nolines nostar b(4) ci(4) wide noparentheses 
esttab pctdp_3TSD using "$resultsfolder/DistGradient_forGraph_3TSD.csv", replace label plain csv compress nogaps nolines nostar b(4) ci(4) wide noparentheses 
	


********************************************************************************

*Model 2: Hedonic regs with sample of homes w/in 5km of a CA, w/ 0-750m pooled	
use "$salesfolder\All_Sales_Final_Cleaned_CA5k", replace

*Need to re-set CA global variables for this sample
local stages pre mid post 
foreach s of local stages {
	global d`s'CA d`s'CA0_750 d`s'CA750_1500 /*d`s'CA1500_5000*/
	}	

*Model with pooled 0-750m CA zone. All CA 5k sample.
reghdfe lnrprice $cntTSD $dpreCA $dmidCA $dpostCA, ///
	absorb(i.mycntyid#i.tranyr i.mycntyid#i.quarter i.mytractid ///
	i.mycntyid#i.tranyr#c.($house)) vce(cluster mycntyid)  compact poolsize(20)
eststo m4
estimates save "$raw_resultsfolder\m4", replace	

*Estimate corresponding intra-area DID treatment effect estimates. This corresponds 
*	to Model 2 results in Table 3 of main text.
eststo TE4: nlcom ///
	(D3MidPre_0_750: ((exp((_b[dmidCA0_750]-_b[dpreCA0_750])-(_b[dmidCA750_1500]-_b[dpreCA750_1500]))-1)*100)) ///
	(D3PostMid_0_750: ((exp((_b[dpostCA0_750]-_b[dmidCA0_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100)) ///
	(D3PostPre_0_750: ((exp((_b[dpostCA0_750]-_b[dpreCA0_750])-(_b[dpostCA750_1500]-_b[dpreCA750_1500]))-1)*100)),  post	
	
*Export regression results and ATT from DD and DDD calculations	
*regression model results
esttab m4 using "$resultsfolder\HedonicReg_Model4_NoCEM.csv", replace label csv compress nogaps nolines star (* 0.10 ** 0.05 *** 0.01) b(4) se(4) scalars(ll N_g) r2 ar2
*ATT Estimates
esttab TE4 using "$resultsfolder\TreatmentEffectEsts_Model4_NoCEM.csv", replace label csv compress nogaps nolines star (* 0.10 ** 0.05 *** 0.01) b(4) se(4) scalars(ll)


********************************************************************************

*Model 3: Hedonic regs with sample of homes w/in 1500m of a CA	
use "$salesfolder\All_Sales_Final_Cleaned_CA1500m", replace	

*reset global vars to only account for TSDs in closer distance bins
*TSD counts	
local vars  cntTSD
foreach v of local vars {
	global `v' `v'0_250 `v'250_500 `v'500_750 `v'750_1000 ///
		`v'1000_1250 `v'1250_1500 /* `v'1500_1750 `v'1750_2000 ///
		`v'2000_2250 `v'2250_2500 `v'2500_2750 `v'2750_3000 ///
		`v'3000_3250 `v'3250_3500 `v'3500_3750 `v'3750_4000 ///
		`v'4000_4250 `v'4250_4500 `v'4500_4750 `v'4750_5000 */
	}

*code up global variables of stage dummies for individual treatment bins.	
local stages pre 
foreach s of local stages {
	global d`s'CA d`s'CA0_750 /*d`s'CA750_1500 d`s'CA1500_5000*/
	}
	*Note: Omit pre-CA 750-1500m b/c that is omitted category for proper 
	*	interpretation with this more focused sample.  It would still run b/c
	*	multiple sites near some sales, but should be excluded for proper 
	*	interpretation. Treatment effect formulas adjusted below, b/c when omitted
	*	the 750-1500m coefficient always accounts for incremental difference. 
local stages /*pre*/ mid post 
foreach s of local stages {
	global d`s'CA d`s'CA0_750 d`s'CA750_1500 /*d`s'CA1500_5000*/
	}

*Model with tract FE, and county x year and county x quarter FEs. 
*	CA only 1500m sample.
reghdfe lnrprice $cntTSD $dpreCA $dmidCA $dpostCA, ///
	absorb(i.mycntyid#i.tranyr i.mycntyid#i.quarter i.mytractid ///
	i.mycntyid#i.tranyr#c.($house)) vce(cluster mycntyid)  compact poolsize(20)	
eststo m5
estimates save "$raw_resultsfolder\m5", replace

*DID treatment effect estimates based on above regression results. This corresponds 
*	to Model 3 results in Table 3 of main text.
eststo TE5: nlcom ///
	(D3MidPre_0_750: ((exp((_b[dmidCA0_750]-_b[dpreCA0_750])-(_b[dmidCA750_1500]))-1)*100)) ///
	(D3PostMid_0_750: ((exp((_b[dpostCA0_750]-_b[dmidCA0_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100)) ///
	(D3PostPre_0_750: ((exp((_b[dpostCA0_750]-_b[dpreCA0_750])-(_b[dpostCA750_1500]))-1)*100)),  post	
  
*Export regression results and ATT from DD and DDD calculations	
*regression model results
esttab m5 using "$resultsfolder\HedonicReg_Model5_NoCEM.csv", replace label csv compress nogaps nolines star (* 0.10 ** 0.05 *** 0.01) b(4) se(4) scalars(ll N_g) r2 ar2
*ATT Estimates
esttab TE5 using "$resultsfolder\TreatmentEffectEsts_Model5_NoCEM.csv", replace label csv compress nogaps nolines star (* 0.10 ** 0.05 *** 0.01) b(4) se(4) scalars(ll)



********************************************************************************


*Model 4: Hedonic regs with sample of homes w/in 1500m of a CA, with CEM weights.	

*bring in main estimating dataset with only matched sales w/in 5k of CA 
use "$salesfolder\All_Sales_Final_Cleaned_CA1500m_CEM_MatchOnly", clear
count
	
*Model with tract FE, and county x year and county x quarter FEs. 
*	CA only 1500m CEM matched sample
reghdfe lnrprice $cntTSD $dpreCA $dmidCA $dpostCA [pweight=cem_weights], ///
	absorb(i.mycntyid#i.tranyr i.mycntyid#i.quarter i.mytractid ///
	i.mycntyid#i.tranyr#c.($house)) vce(cluster mycntyid)  compact poolsize(20)	
eststo m6
estimates save "$raw_resultsfolder\m6", replace
 
*Estimate corresponding intra-area DID treatment effect estimates. This corresponds 
*	to Model 4 results in Table 3 of main text.
eststo TE6: nlcom ///
	(D3MidPre_0_750: ((exp((_b[dmidCA0_750]-_b[dpreCA0_750])-(_b[dmidCA750_1500]))-1)*100)) ///
	(D3PostMid_0_750: ((exp((_b[dpostCA0_750]-_b[dmidCA0_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100)) ///
	(D3PostPre_0_750: ((exp((_b[dpostCA0_750]-_b[dpreCA0_750])-(_b[dpostCA750_1500]))-1)*100)),  post	
	
*Export regression results and ATT from DD and DDD calculations	
*regression model results
esttab m6 using "$resultsfolder\HedonicReg_Model6_CEM.csv", replace label csv compress nogaps nolines star (* 0.10 ** 0.05 *** 0.01) b(4) se(4) scalars(ll N_g) r2 ar2
*ATT Estimates
esttab TE6 using "$resultsfolder\TreatmentEffectEsts_Model6_CEM.csv", replace label csv compress nogaps nolines star (* 0.10 ** 0.05 *** 0.01) b(4) se(4) scalars(ll)

		
*END
